<template>
	<!-- 日志查看 -->
	<div style="height:3000px">
		<v-card>
			<v-card-title>
				<v-row class="mt-2">
					<v-col cols="12" sm="3" md="2">
						<v-select label="日志等级" v-model="systemLogQuery.level" dense outlined :items="levelItems">
						</v-select>
					</v-col>
					<v-col cols="12" sm="3" md="2">
						<v-select label="日志类型" v-model="systemLogQuery.logType" dense outlined :items="logTypeItems">
						</v-select>
					</v-col>
					<v-col cols="12" sm="3" md="2">
						<v-menu v-model="startMenu" :close-on-content-click="false" :nudge-right="40"
							transition="scale-transition" offset-y min-width="auto">
							<template v-slot:activator="{ on, attrs }">
								<v-text-field required v-model="systemLogQuery.sarttime" label="开始时间" readonly
									v-bind="attrs" v-on="on" dense outlined>
								</v-text-field>
							</template>
							<v-date-picker locale="zh-cn" v-model="systemLogQuery.sarttime" @input="startMenu = false">
							</v-date-picker>
						</v-menu>
					</v-col>
					<v-col cols="12" sm="3" md="2">
						<v-menu v-model="endMenu" :close-on-content-click="false" :nudge-right="40"
							transition="scale-transition" offset-y min-width="auto">
							<template v-slot:activator="{ on, attrs }">
								<v-text-field required v-model="systemLogQuery.endtime" label="结束时间" readonly
									v-bind="attrs" v-on="on" dense outlined>
								</v-text-field>
							</template>
							<v-date-picker locale="zh-cn" v-model="systemLogQuery.endtime" @input="endMenu = false">
							</v-date-picker>
						</v-menu>
					</v-col>
					<v-col>
						<v-btn color="primary" @click="LoadPage">查询</v-btn>
						<v-btn class="ml-3" depressed color="primary" @click="RefreshApps">
							刷新</v-btn>
					</v-col>
				</v-row>
			</v-card-title>
			<v-card-text>
				<v-data-table :headers="systemLogHeaderList" :items="systemLogDataList" small fixed-header item-key="id"
					dense class="text-no-wrap" loading-text="正在加载请稍等......" :loading="systemLogLoading"
					:options.sync="systemLogOptions" :footer-props="vuetifyDefaultPage"
					:server-items-length="systemLogTotalCount">

				</v-data-table>
			</v-card-text>
		</v-card>

	</div>
</template>

<script>
	export default {
		name: 'spm_log_see',
		data: () => ({
			systemLogQuery: {
				level: null,
				logType: null,
				sarttime: null,
				endtime: null
			},
			startMenu: false,
			endMenu: false,
			levelItems: [{
					text: 'Info',
					value: '1'
				},
				{
					text: 'Error',
					value: '2'
				}
			],
			logTypeItems: [{
					text: 'Web',
					value: '1'
				},
				{
					text: 'DataBase',
					value: '2'
				},
				{
					text: 'ApiRequest',
					value: '3'
				},
				{
					text: 'Middleware',
					value: '4'
				},
				{
					text: 'Aop',
					value: '5'
				},
				{
					text: 'AutoTask',
					value: '6'
				},
			],
			systemLogHeaderList: [{
					text: '程序',
					align: 'left',
					value: 'application',
					filterable: false,
				},
				{
					text: '日志等级',
					align: 'center',
					value: 'level',
					filterable: false,
				},
				{
					text: '日志类型',
					align: 'center',
					value: 'logtype',
					filterable: false,
				}, {
					text: '日志所属配置',
					align: 'center',
					value: 'logger',
					filterable: false,
				}, {
					text: '日志时间',
					align: 'center',
					value: 'logged',
					filterable: false,
				},
				{
					text: '操作用户名',
					align: 'center',
					value: 'userName',
					filterable: false,
				},
				{
					text: '操作用户Id',
					align: 'center',
					value: 'userId',
					filterable: false,
				},
				{
					text: '标题',
					align: 'left',
					value: 'message',
					filterable: false,
				},
				{
					text: '错误详细消息',
					align: 'left',
					value: 'exception',
					filterable: false,
				},
			],
			systemLogDataList: [],
			systemLogTotalCount: 0,
			systemLogLoading: true,
			systemLogOptions: { //页数
				page: 1,
				//每页行数
				itemsPerPage: 10
			},
			vuetifyDefaultPage: {
				'items-per-page-text': '每页个数',
				'items-per-page-options': [10, 20, 50, 100]
				// 'items-per-page-all-text': '100'
			},
			editAccountBookDialog: false,
			accountBookModel: {}
		}),
		watch: {
			systemLogOptions: {
				handler() {
					this.LoadPage()
				},
				deep: true
			},
		},
		methods: {
			RefreshApps() {
				this.systemLogQuery.level = null
				this.systemLogQuery.logType = null
				this.systemLogQuery.sarttime = null
				this.systemLogQuery.endtime = null
			},
			async LoadPage() {
				this.systemLogLoading = true
				var response = await this.$httpRequest({
					url: `SPM/SystemLog/LoadPage?level=${this.systemLogQuery.level}&
					logType=${this.systemLogQuery.logType}&
					sarttime=${this.systemLogQuery.sarttime}&
					endtime=${this.systemLogQuery.endtime}&
					pageNumber=${this.systemLogOptions.page}&
					pageSize=${this.systemLogOptions.itemsPerPage}`,
					method: 'get',
				})
				if (response.status == 1) {
					this.systemLogDataList = response.data.result
					this.systemLogTotalCount = response.data.pagination.totalRecords
					this.systemLogLoading = false
				} else {
					this.$message.error(response.info)
				}
			},
		},
	}
</script>
